// https : // iai.sh.cn/problem/877
 
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005; // 假设最大的 n 和 m 为 1000
char maze[MAXN][MAXN];
int dist[MAXN][MAXN];
bool visited[MAXN][MAXN];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int main() {
  int n, m;
  cin >> n >> m;

  // 读取迷宫
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> maze[i][j];
    }
  }

  // 初始化
  memset(dist, -1, sizeof(dist));
  memset(visited, false, sizeof(visited));

  // BFS
  queue<pair<int, int>> q;
  q.push({1, 1});
  dist[1][1] = 0;
  visited[1][1] = true;

  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();

    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];

      if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && maze[nx][ny] != '#' && !visited[nx][ny]) {
        dist[nx][ny] = dist[x][y] + 1;
        visited[nx][ny] = true;
        q.push({nx, ny});
      }
    }
  }

  // 输出结果
  if (dist[n][m] == -1) {
    cout << "No solution" << endl;
  } else {
    cout << dist[n][m] << endl;
  }

  return 0;
}
